# 获取按键信号 点亮灯泡
# 出现如下报错 未解决 RuntimeError: Failed to add edge detection
import RPi.GPIO as GP
import time

#11:G17 button
#12:G18 red led
#13:G27 green led

def light_red():
    GP.output(12,1)

def detect(chn):
    print(GP.input(11))
    if GP.input(11):
        GP.output(12,1)
    else:
        GP.output(12,0)

def start():
    GP.setmode(GP.BOARD)
    GP.setwarnings(False)         # 去除GPIO口警告
    GP.setup(11,GP.IN)
    GP.setup(13,GP.OUT)
    GP.setup(12,GP.OUT)

def control_01():
    #GP.add_event_detect(11,GP.RISING,detect,bouncetime=500)
    GP.add_event_detect(11,GP.BOTH,detect)
    # GP.add_event_detect(11,GP.RISING,callback=detect)
    #channel = GP.wait_for_edge(11,GP.FALLING,5000)

    while True:
        #if channel:
        #    detect(1)
        #    print(channel)
        pass
    #    print(1)
     #   time.sleep(0.1)


def close():
    GP.cleanup()


if __name__=='__main__':
    start()
    #try:
    control_01()
    #except Exception as e:
    #except:
    #    print(e)
    print('bye')
    close()
